package com.jay.io.clazz;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class BufferedReaderWriterCls {
	public static void main(String[] args) {
		try {
			File file = new File("out.txt");

			BufferedReader bufInputReader = new BufferedReader(new FileReader(
					file));

			char[] array = new char[1];
			String text = "";
			while (bufInputReader.read(array) != -1) {
				text += array[0];
			}
			System.out.println(text);
			bufInputReader.close();

			System.out.println();

			BufferedWriter bufWriter = new BufferedWriter(new FileWriter(file));
			text += "xxxxx";
			bufWriter.write(text);

			bufWriter.flush();
			bufWriter.close();
		} catch (ArrayIndexOutOfBoundsException e) {
			System.out.println("请指定文件名！");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
